package net.hands.common.ado.query;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 说明:集合数据对象查询 <br>
 * <p>
 * 这是一个开源的软件，请在LGPLv3下合法使用、修改或重新发布。
 * </p>
 * 
 * @author 陈侃(cknet@126.com, 13910090885)
 *         http://code.google.com/p/simpleframework/
 *         http://www.simpleframework.net
 */
public class ListDataObjectQuery<E> extends AbstractDataQuery<E> {
	/**
	 * 集合
	 */
	private List<E> list;

	/**
	 * Constructor Method
	 * 
	 * @update 2012-9-19 下午2:35:56
	 */
	public ListDataObjectQuery() {
		this(null);
	}

	/**
	 * 
	 * Constructor Method
	 * 
	 * @update 2012-9-19 下午2:36:16
	 * @param list
	 */
	public ListDataObjectQuery(final Collection<E> list) {
		this.list = list == null ? new ArrayList<E>() : new ArrayList<E>(list);
	}

	/**
	 * 说明:获得集合
	 * 
	 * @return List<T>
	 * @update 2012-9-19 下午2:36:53
	 */
	public List<E> getList() {
		return list;
	}

	/**
	 * 
	 (non-Javadoc)
	 * 
	 * @see net.hands.common.ado.query.IDataQuery#next()
	 * @update 2012-9-19 下午2:37:13
	 */
	@Override
	public E next() {
		return list.get(i++);
	}

	/**
	 * 
	 (non-Javadoc)
	 * 
	 * @see net.hands.common.ado.query.IDataQuery#getCount()
	 * @update 2012-9-19 下午2:38:34
	 */
	@Override
	public int getCount() {
		if (list != null && count == 0) {
			count = list.size();
		}
		return count;
	}

	@Override
	public boolean hasNext() {
		// TODO Auto-generated method stub
		return i != getCount();
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		list.remove(i);
	}

	@Override
	public int getFetchSize() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public ListDataObjectQuery<E> setFetchSize(int fetchSize) {
		// TODO Auto-generated method stub
		return this;
	}
}
